<?php


namespace Single\Controllers;


use Framework\PBMessageRequest;
use Framework\PBMessageResponse;
use http\Message;
use Phalcon\Di;
use Phalcon\Mvc\Controller;
use School\PBClass;
use School\PBStudent;
use School\PBStudentDegree;
use School\PBStudentInfoReq;
use School\PBStudentListReq;
use School\PBStudentListRsp;
use School\PBUser;
use Single\Logic\StudentInfo;
use Single\Logic\StudentList;

/**
 * Class ApiController
 * @package Single\Controllers
 */
class ApiController extends BaseController
{
    const ProtoBuf = [
        'index' => PBStudentListReq::class,
        'info' => PBStudentInfoReq::class
    ];


    /**
     * 学生列表
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     * @throws \Exception
     */
    public function indexAction()
    {
        # 获取请求数据
        $req = $this->getReq($this);
        # 进行逻辑层处理
        $rsp = (new StudentList($req))->run();
        # 进行返回数据组装返回
        return $this->setRsp($rsp);
    }


    /**
     * 单个学生信息
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     * @throws \Exception
     */
    public function infoAction()
    {
        # 获取请求数据
        $req = $this->getReq($this);
        # 进行逻辑层处理
        $rsp = (new StudentInfo($req))->run();
        # 进行返回数据组装返回
        return $this->setRsp($rsp);
    }
}